#include "iconmanager.h"
#include "iconworker.h"

IconManager::IconManager(QObject *parent)
    : QObject{parent}
{

}

void IconManager::start() {
    stop();

    IconWorker *worker = new IconWorker(this);
    worker->moveToThread(&m_thread);

    connect(this, &IconManager::onRequest, worker, &IconWorker::slotRequest);
//    connect(this, &IconManager::onRequestMap, worker, &IconWorker::slotRequestMap);
//    connect(this, &IconManager::onRequestList, worker, &IconWorker::slotRequestList);
    connect(this, &IconManager::onRequestJson, worker, &IconWorker::slotRequestJson);
    connect(&m_thread, &QThread::finished, worker, &IconWorker::deleteLater);

    m_thread.start();
}

void IconManager::stop()
{
    if (m_thread.isRunning()) {
        m_thread.quit();
        m_thread.wait();
    }
}

qreal IconManager::dpr() const
{
    return m_dpr;
}

void IconManager::setDpr(qreal newDpr)
{
    if (qFuzzyCompare(m_dpr, newDpr))
        return;
    m_dpr = newDpr;
    emit dprChanged();
}
